package com.school.zhaoban.utils;

import java.security.MessageDigest;

/**
 * @author 又菜又爱玩
 * @version 1.0
 * @date 2021/12/25 14:06
 * @blog https://blog.csdn.net/biancheng4/article/details/121727982
 */
public class MD5 {
    /***
     * MD5加密算法：32位md5编码
     * @param
     * @return 加密字符串32位md5编码
     */
    public String md5Encode(String inStr) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");

            byte[] byteArray = inStr.getBytes("UTF-8");
            md5.update(byteArray);
            byte[] md5Bytes = md5.digest(byteArray);
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16) {
                    hexValue.append("0");
                }
                hexValue.append(Integer.toHexString(val));
            }
            return hexValue.toString();

        } catch (Exception e) {
            //System.out.println(e.toString());
            //e.printStackTrace();
            return "";
        }
    }

}
